package com.tanhua.dubbo.server.controller;

import com.tanhua.common.utils.NoAuthorization;
import com.tanhua.dubbo.server.service.IMService;
import com.tanhua.dubbo.server.vo.PageResult;
import com.tanhua.dubbo.server.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName: IMController
 * @Author:王晨晗
 * @Description: 即时通讯控制层
 * @Date: 2022/01/05/19:13
 */
@RestController
@RequestMapping("messages")
public class IMController {
    @Autowired
    private IMService imService;

    /**
     * @description 根据环信用户名获取用户信息
     * @param userName
     * @return
     */
    @GetMapping("userinfo")
    public ResponseEntity queryUserInfoByUserName(@RequestParam("huanxinId") String userName){
        UserInfoVo userInfoVo = imService.queryUserInfoByUserName(userName);
        return ResponseEntity.ok(userInfoVo);
    }


    /**
     * @description 添加好友
     * @param param
     * @return
     */
    @PostMapping("contacts")
    public ResponseEntity contactUser(@RequestBody Map<String, Object> param){
        Long friendId = Long.valueOf(param.get("userId").toString());
        imService.contactUser(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * @description 查询好友列表
     * @param page
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("contacts")
    public ResponseEntity queryContactsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "keyword", required = false) String keyword){
        PageResult pageResult = imService.queryContactList(page , pageSize , keyword);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * @description 获取消息点赞列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("likes")
    public ResponseEntity queryLikeCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                               @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        PageResult pageResult = imService.queryLikeCommentList(page , pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * @description 查询消息喜欢列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("loves")
    public ResponseEntity queryLoveCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                               @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        PageResult pageResult = imService.queryLoveCommentList(page , pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * @description 查询消息评论列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("comments")
    public ResponseEntity queryUserCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                               @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        PageResult pageResult = imService.queryUserCommentList(page , pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * @description 获取公告列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("announcements")
    @NoAuthorization        //无需进行token校验
    public ResponseEntity queryMessageAnnouncementList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                       @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        PageResult pageResult = imService.queryMessageAnnouncementList(page , pageSize);
        return ResponseEntity.ok(pageResult);
    }





}
